package Models;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Date;

public class InvSalesLines {
    final NumberFormat money = new DecimalFormat("$#0.00");
    
    private int id;
    private Customer customer;
    private Date date;
    private DiscountCode discount;
    private double priceOverRide;
    private int qty;
    private Supplies inventoryItem;
    private double unitPrice;
    
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public Customer getCustomer() {
		return customer;
	}
	public void setCustomer(Customer customer) {
		this.customer = customer;
	}
	public Date getDate() {
		return date;
	}
	public void setDate(Date date) {
		this.date = date;
	}
	public DiscountCode getDiscount() {
		return discount;
	}
	public void setDiscount(DiscountCode discount) {
		this.discount = discount;
	}
	public double getPriceOverRide() {
		return priceOverRide;
	}
	public void setPriceOverRide(double priceOverRide) {
		this.priceOverRide = priceOverRide;
	}
	public int getQty() {
		return qty;
	}
	public void setQty(int qty) {
		this.qty = qty;
	}
	public Supplies getInventoryItem() {
		return inventoryItem;
	}
	public void setInventoryItem(Supplies inventoryItem) {
		this.inventoryItem = inventoryItem;
	}
	public double getUnitPrice() {
		return unitPrice;
	}
	public void setUnitPrice(double unitPrice) {
		this.unitPrice = unitPrice;
	}

    /***********************************************************************
     * Standard display for pricing and discount text, etc.
     **********************************************************************/
    /***********************************************************************
     * Get Line Price (returns line item price based on settings of line)
     * @return Price
     **********************************************************************/
    public double getLinePrice(){
        double price = this.getUnitPrice();
        if(this.getPriceOverRide()>0){
            price = this.getPriceOverRide();
        }
        if(this.getDiscount()!=null){
            price = price - (price * this.getDiscount().getDiscNum());
        } 
        return price;
    }

    /***************************************************************************
     * Get Sales Line's subtotal based on settings.
     * @return 
     **************************************************************************/
    public double getLineSubTot(){
        final double subTot = getLinePrice() * (double)this.getQty();
        return subTot;
    }

    /***************************************************************************
     * Get the appropriate discount description based on settings.
     * @return 
     **************************************************************************/
    public String getDiscountText(){
        if(this.getPriceOverRide()>0){
            return "Price Override";
        } else if (this.getDiscount()!=null) {
            return this.getDiscount().getDescription();
        } else {
            return "No Discount";
        }
    }

    /***************************************************************************
     * Get String in CSV format for displaying sales line information.
     * @return 
     **************************************************************************/
    public String getSalesString(){
        String str = "";
        final int numUnits = this.getQty();
        str += this.getInventoryItem().getDisplay();
        str +="," + money.format(getLinePrice());
        str +="," + Integer.toString(numUnits);
        str +="," + money.format(getLineSubTot()) + "\n";
        return str;
    }

}
